package com.wdy.service.impl;

import java.util.List;

import com.wdy.dao.UserDao;
import com.wdy.po.Page;
import com.wdy.po.Result;
import com.wdy.po.User;
import com.wdy.service.UserManager;
import com.wdy.util.PageUtil;
public class UserManagerImpl implements UserManager {

	private UserDao userDao;
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	
	public void saveUser(User user) {
		userDao.save(user);
	}

	
	public void removeUser(User user) {
		userDao.delete(user);
	}

	
	public void updateUser(User user) {
		userDao.attachDirty(user);
	}

	
	public User getUser(Integer id) {
		return userDao.findById(id);
	}


	public List<User> listAll() {
		return userDao.findAll();
	}

	
	public List<User> findByExample(User user) {
		return userDao.findByExample(user);
	}


	public List<User> findByName(String value) {
		return userDao.findByUsername(value);
	}

	public Result listUser(Page page) {
		int totalRecords = this.userDao.getUserCount();
		page = PageUtil.createPage(page, totalRecords);
		List<User> users = (List<User>)this.userDao.getUserByPage(page);     
		return new Result(page, users);
	}

}
